#include <iostream>

using namespace std;
class Solution {
public:
    bool oneEditAway(string first, string second) {
        int length = first.size()-second.size();
        if(length > 1 || length < -1) return false;
        else
        {
           if(first.size() == 0 || second.size() == 0)
               return true;
           int count = 0;
           bool flagStart = true;
           bool flagEnd = true;
           for (int i = 0, j1 = first.size() - 1, j2 = second.size() - 1;;)
           {
               if(i >= j1 && i >= j2) return true;
               if(flagStart)
               {
                   if(first[i] == second[i])
                   {
                       ++i;
                   }
                   else
                   {
                       ++count;
                       flagStart = false;
                   }
               }
               
               if(flagEnd)
               {
                   if(first[j1] == second[j2])
                   {
                       --j1;
                       --j2;
                   }
                   else
                   {
                       ++count;
                       flagEnd = false;
                   }    
               }
               if(count > 1) return false;
           }
           return false;
        }
    }
};
int main()
{
    Solution sol;
    cout << sol.oneEditAway("teacher","bleacher");
    return 0;
}
